package com.gdou.tlias.controller;


import com.gdou.tlias.anno.Log;
import com.gdou.tlias.mapper.DeptMapper;
import com.gdou.tlias.mapper.EmpMapper;
import com.gdou.tlias.pojo.Dept;
import com.gdou.tlias.pojo.Result;
import com.gdou.tlias.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;


@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;
    @Autowired
    private EmpMapper empMapper;
    //查询部门
    @GetMapping
    public Result list(){
        log.info("查询到部门数据");
        List<Dept> deptList = deptService.list();
        return Result.success(deptList);
    }

    //删除部门
    @Log
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("根据id来删除部门:{}",id);
        deptService.delete(id);


        return Result.success() ;
    }



    //新增部门
    @Log
    @PostMapping
    public Result addDept(@RequestBody Dept dept){
        log.info("新增部门");
        deptService.addDept(dept);
        return Result.success();
    }

    //根据id查询
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("修改部门:{}" ,id);
        Dept dept=deptService.getById(id);
        return Result.success(dept);
    }
    //修改部门
    @PutMapping
    public Result update(@RequestBody Dept dept){
        log.info("修改部门：{}",dept);
        deptService.update(dept);
        return Result.success();
    }



}
